import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YaoZhen
 * 代码生成器
 */
public class mp {

    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        final String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("YaoZheng");
        gc.setOpen(false);
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/fmv3?useUnicode=true&useSSL=false&characterEncoding=utf8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        //自定义模块名
//        final String moduleName="users";
//        pc.setModuleName(moduleName);
        pc.setParent("com.lecyon.farm");
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };
        List<FileOutConfig> focList = new ArrayList();
        focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输入文件名称================================模块名（自己设置）
                return projectPath + "/src/main/resources/mapper/mybatis/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);
        mpg.setTemplate(new TemplateConfig().setXml(null));

        // 策略配置**（个性化定制）**
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);

        //实体类自动继承Entity,不需要也可以
//        strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        //小辣椒默认为true
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        //控制层自动继承父类BaseController,不需要也可以
//        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
        //设置要被扫描的表名
        strategy.setInclude(new String[]{
//                "base_gps","details_base_gps","fm_annual_fee","fm_car","fm_car_info","fm_car_install","fm_car_install_init",
//                "fm_coop","fm_history","fm_history_details","fm_region_name","fm_repeat_possible","fm_repeat_work",
//                "fm_user_car","fm_work","fm_work_details","fm_work_total","js_gen_table","js_gen_table_column",
//                "js_job_blob_triggers","js_job_calendars","js_job_cron_triggers","js_job_fired_triggers",
//                "js_job_job_details","js_job_locks","js_job_paused_trigger_grps","js_job_scheduler_state",
//                "js_job_simple_triggers","js_job_simprop_triggers","js_job_triggers","js_sys_area","js_sys_company",
//                "js_sys_company_office","js_sys_config","js_sys_dict_data","js_sys_dict_type","js_sys_employee",
//                "js_sys_employee_office","js_sys_employee_post","js_sys_file_entity","js_sys_file_upload","js_sys_job",
//                "js_sys_job_log","js_sys_lang","js_sys_log","js_sys_menu","js_sys_module","js_sys_msg_inner",
//                "js_sys_msg_inner_record","js_sys_msg_push","js_sys_msg_pushed","js_sys_msg_template","js_sys_office",
//                "js_sys_post","js_sys_role","js_sys_role_data_scope","js_sys_role_menu","js_sys_user",
//                "js_sys_user_data_scope","js_sys_user_role","mydata","test_data","test_data_child","test_tree"
//                "fm_sync_car","fm_sync_information","fm_already_sync_records","object_stores_config", "sys_area_data"
                "data_verification"
        });
//        strategy.setInclude("department");
//        strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(true);
//        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
}
